﻿/*----------------------------------------------------------*
 *                       Game Class                         *
 *                                                          *
 *                Created By: Matthew Hoyes                 *
 *                                                          *
 *      This class is the main class that deals with all    *
 *      the implementation of what is going on in the       *
 *      game.                                               *
 *----------------------------------------------------------*/

#region Using Statements

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

////////////////////////////////////////////////
//////////////////// TEMP //////////////////////
using BrickBreaker.Core;
////////////////////////////////////////////////

//using BBMenuScreen;
//using BBMenuScreen;
//using BBMenuScreen.Screens;


#endregion

namespace BrickBreaker
{
    public class BBGame : Microsoft.Xna.Framework.Game
    {
        BBGlobalController programController;

        /// <summary>
        /// Creates the game.
        /// </summary>
        public BBGame()
        {
            BBGlobalConfig.graphics = new GraphicsDeviceManager(this);
            BBGlobalConfig.content = new ContentManager(Services);
            BBGlobalConfig.content.RootDirectory = "Content";

            this.Window.Title = "M n R Brick Breaker";
            this.IsMouseVisible = true;
        }

        /// <summary>
        /// Initializes the game.
        /// </summary>
        protected override void Initialize()
        {
            programController = new BBGlobalController();
            base.Initialize();
        }

        /// <summary>
        /// Loads the content of the game
        /// </summary>
        protected override void LoadContent()
        {
            //Create a new SpriteBatch, which can be used to draw textures...
            BBGlobalConfig.createSpriteBatch(GraphicsDevice);
            programController.LoadContent();
        }

        /// <summary>
        /// Unloads the content of the game, releasing memory back to the buffer.
        /// </summary>
        protected override void UnloadContent()
        {
            BBGlobalConfig.content.Dispose();
        }

        /// <summary>
        /// Updates the game.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            KeyboardState keyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();
            
            //Allows the game to Exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
                BBGlobalConfig.programState == ProgramState.EXIT)
            {
                programController.ExitGame(this);
            }
            programController.Update(gameTime);

            base.Update(gameTime);
        }

        /// <summary>
        /// Draws the game.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.White);
            
            BBGlobalConfig.getSpriteBatch().Begin(); //begin the drawing of the spritebatch
            programController.Draw(BBGlobalConfig.getSpriteBatch());
            BBGlobalConfig.getSpriteBatch().End(); //end the spritebatch drawing

            base.Draw(gameTime);
        }
    }// end class
}// end namespace
   